# -*- coding: utf-8 -*-
# @File      :面向对象游戏
# @Author    :liaogan
# @Datetime  :2023/3/8 22:39

import time
class Tiger:
    def __init__(self):
        self.name='老虎'
        self.weight=200

    def eat(self,food):
        if food=='meat':
            print('喂食正确，体重加10斤')
            self.weight+=10
        elif food=='grass':
            print('喂食错误，体重减10斤')
            self.weight-=10
        else:
            print('请输入meat或者grass')


    def roar(self):
        print('wow!!!!')
        self.weight-=5

class Sheep:
    def __init__(self):
        self.name='小绵羊'
        self.weight=100

    def eat(self,food):
        if food=='meat':
            print('喂食错误，体重减10斤')
            self.weight-=10
        elif food=='grass':
            print('喂食正确，体重加10斤')
            self.weight+=10
        else:
            print('请输入meat或者grass')

    def roar(self):
        print('咩咩咩!!!!')
        self.weight-=5

class Room:
    def __init__(self,animal):
        self.animal=animal

roomlist=[]

from random import randint
for i in range(10):
    if randint(1,2) ==1:
        animal=Tiger()     #实例化一个老虎
    else:
        animal=Sheep()     #实例化一个羊
    room=Room(animal)      #实例化一个房间放入一个动物
    roomlist.append(room)  #把房间的实例放入列表
print(roomlist)

start_time=time.time()
while time.time() - start_time <= 10:
    room_number = randint(0,9)#在0-9之间随机取一个数字
    random_room=roomlist[room_number]#选择一个房间
    load1=input(f'当前访问的是{room_number+1}号房间，请问是敲门还是喂食，1敲门，2喂食')
    if load1 == '1':
        random_room.animal.roar() #调用房间的动叫的方法

    elif load1 == '2':
        food=input('请选择喂的食物meat/grass:')
        if food.lower()in('meat','grass'):
            random_room.animal.eat(food)  #调用房间动物吃的方法
        else:
            print('你输入的食物不正确')
    else:
        print('游戏结束')
        for i in range(len(roomlist)):
            print(f'{i + 1}号房间的动物是{roomlist[i].animal.name},体重是{roomlist[i].animal.weight}')



